<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='global-property-'>/**
</span> * @ignore
 * localStorage support for ie&lt;8
 * @author yiminghe@gmail.com
 */
KISSY.add(&quot;editor/plugin/local-storage&quot;, function (S, Editor, Overlay, FlashBridge) {
    var ie = document.documentMode || S.UA.ie;

    // 原生或者已经定义过立即返回
    // ie 使用 flash 模拟的 localStorage，序列化性能不行
    if ((!ie || ie &gt; 8) &amp;&amp; window.localStorage) {
        //原生的立即可用
        return window.localStorage;
    }

    // 国产浏览器用随机数/时间戳试试 ! 是可以的
    var swfSrc = Editor.Utils.debugUrl(&quot;plugin/local-storage/assets/swfstore.swf?t=&quot; + (+new Date()));

    var css = {
        width: 215,
        border: '1px solid red'
    }, reverseCss = {
        width: 0,
        border: 'none'
    };

    //Dialog 不行
    var o = new Overlay({
        prefixCls: 'ks-editor-',
        elStyle: {
            background: 'white'
        },
        width: &quot;0px&quot;,
        content: &quot;&lt;h1 style='&quot; + &quot;text-align:center;'&gt;请点击允许&lt;/h1&gt;&quot; +
            &quot;&lt;div class='storage-container'&gt;&lt;/div&gt;&quot;,
        zIndex: Editor.baseZIndex(Editor.ZIndexManager.STORE_FLASH_SHOW)
    });
    o.render();
    o.show();

    var store = new FlashBridge({
        src: swfSrc,
        render: o.get(&quot;contentEl&quot;).one('.storage-container'),
        params: {
            flashVars: {
                useCompression: true
            }
        },
        attrs: {
            height: 138,
            width: '100%'
        },
        methods: [&quot;setItem&quot;, &quot;removeItem&quot;, &quot;getItem&quot;, &quot;setMinDiskSpace&quot;, &quot;getValueOf&quot;]
    });

    // 必须在视窗范围内才可以初始化，触发 contentReady 事件
    S.ready(function () {
        setTimeout(function () {
            o.center();
        }, 0);
    });

    store.on(&quot;pending&quot;, function () {
        o.get('el').css(css);
        o.center();
        o.show();
        // 轮训，直到用户允许
        setTimeout(function () {
            store.retrySave();
        }, 1000);
    });

    store.on(&quot;save&quot;, function () {
        o.get('el').css(reverseCss);
    });

    var oldSet = store.setItem;

    S.mix(store, {
        _ke: 1,
        getItem: function (k) {
            return this['getValueOf'](k);
        },
        retrySave: function () {
            var self = this;
            self.setItem(self.lastSave.k, self.lastSave.v);
        },
        setItem: function (k, v) {
            var self = this;
            self.lastSave = {k: k, v: v};
            oldSet.call(self, k, v);
        }
    });

    //非原生，等待flash通知
    store.on(&quot;contentReady&quot;, function () {
        store._ready = 1;
    });

    /*
     &quot;quotaExceededError&quot;
     &quot;error&quot;
     &quot;save&quot;
     &quot;inadequateDimensions&quot;
     */

    return store;
}, {
    //important
    //不能立即运行，ie6 可能会没有 domReady 添加 flash 节点
    //导致：operation aborted
    &quot;requires&quot;: [&quot;editor&quot;, &quot;overlay&quot;, &quot;./flash-bridge&quot;]
});</pre>
</body>
</html>
